package de.puc.defencetower.view.tui;

import org.apache.log4j.Logger;

import de.puc.defencetower.controller.iGameControllerActionListener;
import de.puc.defencetower.model.Grass;
import de.puc.defencetower.model.Map;
import de.puc.defencetower.model.MapCell;
import de.puc.defencetower.model.MapElement;
import de.puc.defencetower.model.Monster;
import de.puc.defencetower.model.Street;
import de.puc.defencetower.model.Tower;
import de.puc.defencetower.view.tui.console.CellView;
import de.puc.defencetower.view.tui.console.GrassView;
import de.puc.defencetower.view.tui.console.MonsterView;
import de.puc.defencetower.view.tui.console.StatsView;
import de.puc.defencetower.view.tui.console.StreetView;
import de.puc.defencetower.view.tui.console.TowerView;

public class TUIWindow {

	private Map map;
	private StatsView statsView;
	
	private static Logger logger = Logger.getLogger("de.puc.defencetower.MapWindow");

	public TUIWindow(iGameControllerActionListener controler, Map map) {
		this.map = map;
		statsView = new StatsView(map);
		
		new TUIFPSTimer(this).start();
		
	}

	public void print() {

		// clear
		logger.info("\n\n\n\n\n\n");

		// stats
		statsView.print();
		
		// map
		MapCell[][] cells = map.getCells();
		for (int i = 0; i < cells.length; i++) {
			String sZ = "";
			for (int j = 0; j < cells[i].length; j++) {
				MapCell mc = cells[i][j];
				CellView cv = null;
				for (MapElement mapElement : mc.getMapElements()) {

					if (mapElement instanceof Street) {
						cv = new StreetView(mc, (Street)mapElement);
					}
					if (mapElement instanceof Grass) {
						cv = new GrassView(mc, (Grass)mapElement);
					}
					if (mapElement instanceof Monster) {
						cv = new MonsterView(mc, (Monster)mapElement);
					}
					if (mapElement instanceof Tower) {
						cv = new TowerView(mc, (Tower)mapElement);
					}
				}

				sZ += cv.getChar();
			}
			logger.info(sZ);
		}

	}
}
